﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IBLL;
using IDAL;
using System.Security.Cryptography;

namespace BLL
{
    public class UserInfoEdit : IUserInfoEdit
    {
        IUserInfo dal = DALFactory.DataAccess.UpdateUser();


        public void UpdateUserInfo(DataMode.userinfo ui, string name)
        {
            ui.password = GetMD5String(ui.password);
            dal.UpdateUserInfo(ui,name);
            return;
        }

       

        public IQueryable GetUserInfoByName(string name)
        {
            return dal.GetUserInfoByName(name);
        }

        public DataMode.userinfo getuserinfo(string name)
        {

            return dal.getuserinfo(name);
        }

        public static string GetMD5String(string str)
        {
            MD5 md5 = MD5.Create();
            byte[] b = Encoding.UTF8.GetBytes(str);
            byte[] md5b = md5.ComputeHash(b);
            md5.Clear();
            StringBuilder sb = new StringBuilder();
            foreach (var item in md5b)
            {
                sb.Append(item.ToString("x2"));
            }
            return sb.ToString();
        }
    }
}
